package com.uppfind.framework.dao.api.common.params;


import com.uppfind.framework.dao.api.common.Param;

import java.io.Serializable;

public class QueryParam extends Param implements Serializable {

    public static final int DEFAULT_PAGE_SIZE = 10;
    private static final long serialVersionUID = 7941767360194797891L;
    protected boolean forUpdate = false;
    //分页查询的时候，计算total
    protected boolean forTotal = false;
    private int pageSize = DEFAULT_PAGE_SIZE; // 每页的记录数
    /**
     * 是否进行分页，默认为false
     */
    private boolean paging = false;
    /**
     * 当前页码，从1开始记数
     */
    private long currentPage = 1;
    private long start = 0; //当前页第一条数据在List中的位置,从0开始

    public static QueryParam build() {
        return new QueryParam();
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public long getStart() {
        if (currentPage - 1 >= 0) {
            return (currentPage - 1) * pageSize;
        }
        return 0;
    }

    public void setStart(long start) {
        this.start = start;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public boolean isPaging() {
        return paging;
    }

    public void setPaging(boolean paging) {
        this.paging = paging;
    }

    public long getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(long currentPage) {
        this.currentPage = currentPage;
    }

    public boolean isForUpdate() {
        return forUpdate;
    }

    public void setForUpdate(boolean forUpdate) {
        this.forUpdate = forUpdate;
    }

    public boolean isForTotal() {
        return forTotal;
    }

    public void setForTotal(boolean forTotal) {
        this.forTotal = forTotal;
    }
}
